﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CARMSBusiness.InterFace;
using CARMSData.EntityClasses;

namespace CARMSBusiness
{
    public class GActionBusiness
    {
        /// <summary>
        /// G102表
        /// G102-1	varchar	4	N	事件處理碼
        ///G102-2	varchar	16	N	處理單號
        ///G102-3	varchar	10	N	訊息等級
        ///G102-4	nvarchar	100	N	通知內容
        ///G102-5	varchar	10	N	通知部門
        ///G102-6	varchar	8	N	通知對象﹕通知對象為空白時是對所有人員發佈
        ///G102-7	varchar	50	Y	(一級,二級,三級,四級,五級)審核人職稱
        ///G102-8	varchar	4	N	處理任務   --->publicconst.
        ///G102-9	nvarchar	100	N	督導主管,部門主管
        ///G102-10	nvarchar	30	N	訊息載體群
        ///G102-11	varchar	4	N	訊息條保留天數
        /// </summary>
        /// <param name="strMethodName">处理任务</param>
        /// <param name="reportHeader"></param>
        public static void ExcuteG102Action(string strMethodName, string strOpeartionUser, ReportHeaderEntity reportHeader, G102Entity g102Entity)
        {
            switch (strMethodName)
            {
                case PublicConst.G102Method.Action1:   //copy message content to g100
                    ExcueteMessageByTemplateG102(strOpeartionUser, reportHeader, g102Entity);
                    break;
                case PublicConst.G102Method.Action2:

                    break;
                case PublicConst.G102Method.Action3:

                    break;
                case PublicConst.G102Method.Action4:

                    break;
                case PublicConst.G102Method.Action5:

                    break;
                case PublicConst.G102Method.Action6:  //发送email
                    ExcueteMailByTemplateG102(strOpeartionUser, reportHeader, g102Entity);
                    break;
                case PublicConst.G102Method.Action7:

                    break;
                case PublicConst.G102Method.Action8:

                    break;
                case PublicConst.G102Method.Action9:

                    break;
                case PublicConst.G102Method.Action10:

                    break;
                case PublicConst.G102Method.Action11:

                    break;
                case PublicConst.G102Method.Action12:

                    break;
                case PublicConst.G102Method.Action13:

                    break;
            }
        }

        #region 消息通知


        /// <summary>
        ///G100-1				來源單號
        /// G100-2				訊息等級
        ///  G100-3				通知內容
        /// G100-4				通知部門
        /// G100-5				通知對象
        /// G100-6				發佈時間
        /// G100-7				發佈人員
        /// G100-8				回覆內容
        /// G100-9				回覆時間(系統產生)
        /// G100-10             讯息失效时间	
        ///
        ///G102-3	varchar	10	N	訊息等級
        ///G102-4	nvarchar	100	N	通知內容
        ///G102-5	varchar	10	N	通知部門
        ///G102-6	varchar	8	N	通知對象﹕通知對象為空白時是對所有人員發佈
        ///G102-7	varchar	50	Y	(一級,二級,三級,四級,五級)審核人職稱
        ///G102-8	varchar	4	N	處理任務
        ///G102-9	nvarchar	100	N	督導主管,部門主管
        ///G102-10	nvarchar	30	N	訊息載體群
        ///G102-11	varchar	4	N	訊息條保留天數
        /// </summary>
        /// <param name="reportHeader"></param>
        /// <param name="g102Entity"></param>
        private static void ExcueteMessageByTemplateG102(string strOpeartionUser, ReportHeaderEntity reportHeader, G102Entity g102Entity)
        {

            var g100Entity = new G100Entity
                                 {
                                     Gid = Guid.NewGuid(),
                                     ParentId = g102Entity.Gid,
                                     G1001 = reportHeader.ReportCode,  
                                     G1002 = g102Entity.G1023,
                                     G1003 = g102Entity.G1024,
                                     G1004 = g102Entity.G1025,
                                     G1005 = g102Entity.G1026,
                                     G1006 = DateTime.Now.ToString(ApplicationConfiguration.DateTimeFormat),
                                     G1007 = strOpeartionUser,
                                     G1008 = string.Empty,
                                     G1009 = string.Empty,
                                     G10010 = "Message" //DateTime.Now.AddDays(Convert.ToDouble(g102Entity.G10211)).ToString(ApplicationConfiguration.DateTimeFormat),   //subject
                                 };
            g100Entity.Save();

        }
        #endregion

        #region send mail
        /// <summary>
        /// 
        /// MailID	uniqueidentifier	Unchecked
        ///MailTo	nvarchar(100)	Checked
        ///MailCC	nvarchar(100)	Checked
        ///MailBcc	nvarchar(100)	Checked
        ///Detail	ntext	Checked
        ///CreateDate	datetime	Unchecked
        ///SendDate	datetime	Checked
        ///CreateUserID	uniqueidentifier	Unchecked
        ///Subject	nvarchar(500)	Checked
        ///RelativeID	uniqueidentifier	Unchecked
        ///Status	int	Unchecked
        ///Deleted	bit	Unchecked
        ///SendTimes	int	Unchecked
        ///SendError	ntext	Checked
        ///         ///
        ///G102-3	varchar	10	N	訊息等級
        ///G102-4	nvarchar	100	N	通知內容
        ///G102-5	varchar	10	N	通知部門
        ///G102-6	varchar	8	N	通知對象﹕通知對象為空白時是對所有人員發佈
        ///G102-7	varchar	50	Y	(一級,二級,三級,四級,五級)審核人職稱
        ///G102-8	varchar	4	N	處理任務
        /// </summary>
        /// <param name="strOpeartionUser"></param>
        /// <param name="reportHeader"></param>
        /// <param name="g102Entity"></param>
        private static void ExcueteMailByTemplateG102(string strOpeartionUser, ReportHeaderEntity reportHeader, G102Entity g102Entity)
        {
            var mailTask = new MailTaskEntity()
                               {
                                   MailId = Guid.NewGuid(),
                                   MailTo =g102Entity.G10215,  //AdminBusiness.GetUserMailListByLoginNames(g102Entity.G1028),
                                   MailCc = string.Empty,
                                   MailBcc = string.Empty,
                                   Detail = g102Entity.G1024,
                                   CreateDate = DateTime.Now,
                                   CreateUserName = strOpeartionUser,
                                   SendDate = DateTime.Now,
                                   Subject = "Email Notice:" + reportHeader.ReportCode,
                                   RelativeId = reportHeader.ReportHeaderId,
                                   Status = 0,
                                   Deleted = false,
                                   SendTimes = 0,
                                   SendError = string.Empty
                               };
            mailTask.Save();
        }

        #endregion

        #region  对内外通讯的具体方法
        #endregion
    }
}
